package algorithm.shipinke;

import java.util.Stack;

public class ReverseLinkedList {
    public static void main(String[] args) {
//        Node E = new Node("A", null);
        Node E = new Node("E", null), D = new Node("D", E), C = new Node("C", D),
                B = new Node("B", C), A = new Node("A", B);
        reversePrint(A);

    }

    public static void reversePrint(Node node){
        Stack<Node> nodeStack = new Stack<Node>();

        Node wait2Push = node;

        while (wait2Push != null) {
            nodeStack.push(wait2Push);
            wait2Push = wait2Push.nextNode;
        }

        while (!nodeStack.empty()) {
            Node popNode = nodeStack.pop();
            System.out.println(popNode);
        }
    }
}


class Node{
    String name;

    Node nextNode;

    public Node(String name, Node nextNode) {
        this.name = name;
        this.nextNode = nextNode;
    }

    @Override
    public String toString() {
        return "Node{" +
                "name='" + name + '\'' +
                '}';
    }
}
